cmake_minimum_required(VERSION 3.0)

message(STATUS "upload CMAKE_SOURCE_DIR: ${CMAKE_SOURCE_DIR}")
message(STATUS "upload CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")

include(${CMAKE_SOURCE_DIR}/include/common/CMakeLists.txt)

set(UPLOAD_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
set(UPLOAD_SRCPATH ${CMAKE_SOURCE_DIR}/src/upload)
set(UPLOAD_SOURCE
    ${UPLOAD_SRCPATH}/upload.c
)

add_executable(upload ${UPLOAD_SOURCE} ${COMMON_SOURCES})
target_include_directories(upload PRIVATE
    ${UPLOAD_INCLUDE_DIRS}
    ${COMMON_INCLUDE_DIRS}
    ${MySQL_INCLUDE_DIRS}
    ${Hiredis_INCLUDE_DIRS}
    ${FCGI_INCLUDE_DIRS}
)

if (FCGI_FOUND)
    target_link_libraries(upload PRIVATE ${FCGI_LIBRARIES})
    message(STATUS "Link_libraries FCGI_LIBRARIES = ${FCGI_LIBRARIES}")
endif()

if(MySQL_FOUND)
    target_link_libraries(upload PRIVATE ${MYSQL_LIBRARIES})
    message(STATUS "Link_libraries MySQL_LIBRARIES = ${MYSQL_LIBRARIES}")
endif()

if (OpenSSL_FOUND)
    target_link_libraries(upload PRIVATE ${OPENSSL_LIBRARIES})
    message(STATUS "Link_libraries OPENSSL_LIBRARIES = ${OPENSSL_LIBRARIES}")
endif()

if(Hiredis_FOUND)
    target_link_libraries(upload PRIVATE ${Hiredis_LIBRARIES})
    message(STATUS "Link_libraries Hiredis_LIBRARIES = ${Hiredis_LIBRARIES}")
endif()

target_link_libraries(upload PRIVATE m)